namespace EyeOpen.Validation.Mapping
{
    using System;
    using System.Collections.Generic;
    using System.Linq.Expressions;
    using EyeOpen.Extensions;

    /// <summary>
    /// Defines fluent interface logic for validate an entity.
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public abstract class ValidationMapping<T> where T : class
    {
        private readonly IList<PropertyMap> propertiesMapped;

        /// <summary>
        /// Initializes a new instance of the <see cref="ValidationMapping&lt;T&gt;"/> class.
        /// </summary>
        protected ValidationMapping()
        {
            propertiesMapped = new List<PropertyMap>();
            Map();
        }

        /// <summary>
        /// Gets the properties mapped.
        /// </summary>
        /// <value>The properties mapped.</value>
        public IEnumerable<PropertyMap> PropertiesMapped
        {
            get
            {
                return propertiesMapped;
            }
        }

        protected abstract void Map();
        
        protected ValidationPropertyMap Map(Expression<Func<T, object>> expression)
        {
            var propertyName = expression.GetPropertyName();

            var validationPropertyMap = new ValidationPropertyMap(propertyName);

            propertiesMapped.Add(validationPropertyMap);

            return validationPropertyMap;
        }
    }
}